from pack.CraUrl import CraUrl
from util.openExcel import readTaobaoDataSourceExcel

#
class WordCache:
    def __init__(self,filePath=None,outFilePath=None) -> None:
        self.filePath = filePath
        if outFilePath == None :
            self.outFilePath = str(filePath).split(".")[0]+".txt"
        else:
            self.outFilePath = outFilePath
        self.words = set()
        self.urls=[]
        self.outWords= set()
        self.loadFileExcel()
        super().__init__()

    def loadFileExcel(self):
        if(self.filePath!=None):
            data = readTaobaoDataSourceExcel(self.filePath)
            for index in range(len(data)):
                val = str(data[index]).strip()
                self.words.add(val)
                self.urls.append(CraUrl(url="https://s.taobao.com/search",params={'q':str(data[index]).strip(),'s':0}))


    def clear(self):
        self.outFilePath=None;
        self.filePath=None
        self.words=set()
        self.outWords=set()
        self.urls = []


